<div id="an_checkbox_box">
	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">子题目内容</label>
		<div class="layui-input-block">
			<!-- 加载编辑器的容器 -->
		    <script id="container2" name="duoxuan[title]" type="text/plain">
		        <{$topic_info.subject_text|default:""}>
		    </script>
		</div>
	</div>

	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">题目答案A</label>
			<div class="layui-input-block">
				<input type="text" name="duoxuan[checkbox_text][1]" lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">
			</div>
		</div>
		
		<div class="layui-inline">
			<input type="checkbox" name="duoxuan[checkbox][1]" checked="checked" value="1" title="正确答案">
		</div>

		<div class="layui-inline">
			<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="0" href="javascript:;"><i class="layui-icon"></i></a>
		</div>
	</div>

	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">题目答案B</label>
			<div class="layui-input-block">
				<input type="text" name="duoxuan[checkbox_text][2]" lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">
			</div>
		</div>
		
		<div class="layui-inline">
			<input type="checkbox" name="duoxuan[checkbox][2]" value="1" title="正确答案">
		</div>

		<div class="layui-inline">
			<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="0" href="javascript:;"><i class="layui-icon"></i></a>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label"></label>
		<a href="javascript:;" class="layui-btn layui-btn-primary add_checkbox"><i class="layui-icon"></i>新增选项</a>
	</div>
</div>

<div class="layui-form-item layui-form-text">
	<label class="layui-form-label">答案解析</label>
	<div class="layui-input-block">
		<textarea name="duoxuan[analysis]" placeholder="请输入内容" class="layui-textarea"></textarea>
	</div>
</div>

<script>
	layui.use(['form'], function(){
		var form = layui.form();
		form.render();
		
		$(".add_checkbox").click(function(){
			var _this = $(this);
			var letter = new Array();
			letter = <{$letter|json_encode}>;
			var checkbox_total = _this.closest("#an_checkbox_box").find("input[type='checkbox']").length;
			var index = checkbox_total+1;
			var html = '<div class="layui-form-item">';
			html +=	'<div class="layui-inline">';
			html +=	'<label class="layui-form-label">题目答案'+letter[index-1]+'</label>';
			html +=	'<div class="layui-input-block">';
			html +=	'<input type="text" name="duoxuan[checkbox_text]['+index+']" lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">';
			html +=	'</div>';
			html +=	'</div>';
				
			html +=	'<div class="layui-inline">';
			html +=	'<input type="checkbox" name="duoxuan[checkbox]['+index+']" value="1" title="正确答案">';
			html +=	'</div>';
			html +=	'<div class="layui-inline">';
			html +=	'<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="0" href="javascript:;"><i class="layui-icon"></i></a>';
			html +=	'</div>';
			html +=	'</div>';
			_this.closest(".layui-form-item").before(html);
			form.render('checkbox');
		});

		$( document ).on( "click", ".delete_result", function() {
		    var _this = $(this);
			var resultid = _this.attr("resultid");
			var parent = _this.closest(".layui-form-item").parent();
			var total = parent.find("input[type='checkbox']").length;
			var id = parent.attr("id");
			if(total <= 2){
				layer.msg("无法删除，因为至少需要两个答案", {icon:5, anim: 5});
				return false;
			}
			checked_dom = 0;
			$("#an_checkbox_box input[type='checkbox']").each(function (index,domEle){
				if($(domEle).next().hasClass("layui-form-checked")){
					checked_dom += 1;
				}
			});
			if(checked_dom <= 2 && _this.closest(".layui-form-item").find("input[type='checkbox']").is(':checked')){
				layer.msg("无法删除，因为至少需要两个正确答案", {icon:5, anim: 5});
				return false;
			}
			if(resultid > 0){
				if(confirm('删除后将无法还原,确定要删除吗?')){
				
				}else{
					return false
				}
				$.ajax({
					type: "POST",
					url: "/topic/ignore_del_topic_result",
					dataType:"json",
					data:{resultid:resultid},
					success: function(result){
						layer.close(ii);
						if(result.error == 1){
							layer.msg(result.msg, {icon:5, anim: 5});
							return false;
						}
						form.render('select');
					}
				});
			}
			_this.closest(".layui-form-item").remove();
	  	});
	});

</script>